const express = require('express');
const mysql = require('mysql');
const sign = require('../../libs/common-util');
const config = require('../../config');

const apiUser = require('./user/api_user');

const db = mysql.createPool({
    host : config.databaseHost,//,'localhost',
    user : config.databaseUser,//'root',
    password : config.databasePwd,//'Deng%)#@real5032',
    database : config.database,//'learner'
});

module.exports = function () {
    let router = express.Router();
    router.use('/user', apiUser());
    router.get('/getBanners', (req, res)=> {
        //do db query
        db.query(`SELECT * FROM banner_table`, (err, data)=>{
            if (err) {
                res.status(500).send({code:"0", msg : "data error"}).end();
            }else {
                res.send({code:"0", msg : "data error"}).end();
            }
        });
    });

    router.get('/getTest', (req, res)=>{
        console.log('getTest', req.query);
        let reqParam = req.query;
        res.send({code:"0", msg : "this is getTest", data : reqParam}).end();
    });

    router.post('/postTest', (req, res)=>{
        console.log('postTest', req.body);
        let reqParam = req.body;
        res.send({code:"0", msg : "this is post test", data : reqParam}).end();
    });

    return router;
}

